<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Recibo_i extends MN_Controller {

    function __construct() {
        parent::__construct();
        $this->load->database();
        $this->load->helper(array('url', 'form'));
        $this->load->library('ion_auth');
    }

    public function genera() {
      if (!$this->ion_auth->logged_in() || (!$this->ion_auth->is_admin() && !$this->ion_auth->is_secretary() && !$this->ion_auth->is_financial()) ) {
            $this->session->set_flashdata('message', 'No pertence al grupo de Docentes');
            redirect('auth/login', 'refresh');
        }
        $this->data['user'] = $this->ion_auth->get_user_username();
        
        $this->load->model('Matricula_Model');
        $this->load->model('Institucion_Model');

        $this->data['cuentas']=$this->Institucion_Model->getCuentasInstitucionNombre("INSTITUTO TECNOLOGICO SUPERIOR SUDAMERICANO LOJA");
        $this->data['id_matr'] = $this->input->post('id_matr'); 

        $this->data['apellido_pers'] = $this->input->post('apellido_pers');
        $this->data['nombre_pers'] = $this->input->post('nombre_pers');
        $this->data['cedula_pers'] = $this->input->post('cedula_pers');
        $this->data['fono_pers'] = $this->input->post('fono_pers');
        $this->data['celular_pers'] = $this->input->post('celular_pers');
        $this->data['direccion_pers'] = $this->input->post('direccion_pers');
        $this->data['monto_canc_matr'] = $this->input->post('monto_canc_matr');
        $this->data['nom_doc_pago_mat'] = $this->input->post('nom_doc_pago_mat');
        $this->data['nro_comp_pago_mat'] = $this->input->post('nro_comp_pago_mat');
        $this->data['lote_doc_pago_mat'] = $this->input->post('lote_doc_pago_mat');
        $this->data['ref_doc_pago_mat'] = $this->input->post('ref_doc_pago_mat');
        $this->data['monto_efec_doc_pago'] = $this->input->post('monto_efec_doc_pago');
        $this->data['monto_rest_doc_pago'] = $this->input->post('monto_rest_doc_pago');
        $this->data['tipo_doc_pago_mat'] = $this->input->post('tipo_doc_pago_mat');
        $this->data['fechadep_doc_pago_mat'] = $this->input->post('fechadep_doc_pago_mat');
        
        //fechadep_doc_pago_mat2
        //$this->data['ide_lec']=$this->input->post('ide_lec');
        $this->data['concepto'] = $this->input->post('concepto');
        $this->data['ide_lec'] = $this->input->post('ide_lec');
        //$nro=$this->Matricula_Model->getNroCredito($this->input->post('ide_lec'))+1;
        
        //$this->data['nro_recibo'] =$nro;
        $this->data['pagina'] =$this->uri->segment(3);
        
        //echo $this->uri->segment(3);
        
        //$url=$_SERVER['REQUEST_URI'];
         if($this->session->flashdata('enviardetalle')){
            $detalle=$this->session->flashdata('enviardetalle');   
        }else{
            $detalle="";
        }
        $this->data['detalle'] = $detalle;
           

       
        $this->_render('recibo_i/new');
    }

    public function ingresodatos() {
      if (!$this->ion_auth->logged_in() || (!$this->ion_auth->is_admin() && !$this->ion_auth->is_secretary() && !$this->ion_auth->is_financial())  ) {
            $this->session->set_flashdata('message', 'No pertence al grupo de Docentes');
            redirect('auth/login', 'refresh');
        }
        $this->data['user'] = $this->ion_auth->get_user_username();
        
        
         $this->load->helper('numeros');
         $this->load->model('Matricula_Model');
        if($this->session->flashdata('detalle')){
         $detalle=$this->session->flashdata('detalle');   
        }else{
            $detalle="";
        }
          
        //print_r($detalle);
        
        $id_matr=$this->input->post('id_matr');
        
        
        $this->data['apellido_pers'] = $this->input->post('apellido_pers');
        $this->data['nombre_pers'] = $this->input->post('nombre_pers');
        $this->data['cedula_pers'] = $this->input->post('cedula_pers');
        $this->data['fono_pers'] = $this->input->post('fono_pers');
        $this->data['celular_pers'] = $this->input->post('celular_pers');
        $this->data['direccion_pers'] = $this->input->post('direccion_pers');
        $this->data['email_inst_pers'] = $this->input->post('email_inst_pers');
        $this->data['monto_canc_matr'] = $this->input->post('monto_canc_matr');
        $this->data['monto_letras'] = num_to_letras($this->input->post('monto_canc_matr'));
        $this->data['nom_doc_pago_mat'] = $this->input->post('nom_doc_pago_mat');

        $this->data['nro_comp_pago_mat'] = $this->input->post('nro_comp_pago_mat');
        $this->data['lote_doc_pago_mat'] = $this->input->post('lote_doc_pago_mat');
        $this->data['ref_doc_pago_mat'] = $this->input->post('ref_doc_pago_mat');
        $this->data['monto_efec_doc_pago'] = $this->input->post('monto_efec_doc_pago');
        $this->data['monto_rest_doc_pago'] = $this->input->post('monto_rest_doc_pago');
        $this->data['fechadep_doc_pago_mat'] = $this->input->post('fechadep_doc_pago_mat');
        
        $this->data['tipo_doc_pago_mat'] = $this->input->post('tipo_doc_pago_mat');
        $this->data['pagina'] = $this->input->post('pagina');
        $this->data['concepto'] = $this->input->post('concepto');
        $nro = $this->Matricula_Model->getNroRecibo($this->input->post('ide_lec')) + 1;
        $this->data['nro_recibo'] = $nro;
        $this->data['detalle'] = $detalle;
        
        //$nro=$this->Matricula_Model->getNroRecibo($this->input->post('ide_lec'))+1;

        $recibo = array(
            "nro_recibo_mat" =>  $nro,
            "tipo_doc_pago_mat" => $this->input->post('tipo_doc_pago_mat'),
            "nom_doc_pago_mat" =>$this->input->post('nom_doc_pago_mat'),
            "nro_comp_pago_mat" => $this->input->post('nro_comp_pago_mat'),
            "lote_doc_pago_mat" => $this->input->post('lote_doc_pago_mat'),
            "ref_doc_pago_mat" => $this->input->post('ref_doc_pago_mat'),
            "id_matr" => $id_matr);
        //print_r($recibo);
        
        $this->Matricula_Model->grabarRecibo($recibo);
        $montos = array(
            "monto_efec_doc_pago" => $this->input->post('monto_efec_doc_pago'),
            "monto_rest_doc_pago" =>$this->input->post('monto_rest_doc_pago'),
            "id_matr" => $id_matr);
        $this->Matricula_Model->grabarMontos($montos);
        $fechadep=$this->input->post('fechadep_doc_pago_mat');
        if (!empty($fechadep)) {
            $fechadep=date("Y-m-d", strtotime($this->input->post('fechadep_doc_pago_mat'), 0));
            $this->Matricula_Model->actualizafechadeposito($fechadep, $id_matr);
        }else{
            $this->Matricula_Model->actualizafechadeposito($fechadep, $id_matr);
        }
        if(isset($_POST['detalle1']) && $_POST['detalle1']!="" ){
             $detalle1 = unserialize(stripslashes($_POST['detalle1']));
            //print_r($detalle1);
            $this->data['detalle1'] = $detalle1;
            
        }        

        $html = $this->load->view('recibo_i/recibo_pago', $this->data, true);
        $path = $this->dompdf_lib->createPDF($html, 'myfilename1', false,"a3");

        $this->data['path'] = $path;
        

        $this->_render('recibo_i/reporte1');
    }

}


